package com.tommy.jiami.ui;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.tommy.jiami.MyApplication;
import com.tommy.jiami.R;

public class SplashActivity extends AppCompatActivity {

    AlertDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        if (MyApplication.getSharedPreferences().getInt("password_type", -1) == -1) {
            showSettingGuideDialog();
        } else
            initViews();

    }

    public void showSettingGuideDialog() {
        dialog = new AlertDialog.Builder(this)
                .setTitle(R.string.choose_password_type)
                .setItems(R.array.password_type, null)
                .setCancelable(false)
                .show();
        dialog.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(SplashActivity.this, SettingPasswordActivity.class)
                        .putExtra("password_type", position);
                if(position==2&& Build.VERSION.SDK_INT<23){
                    Toast.makeText(SplashActivity.this,R.string.system_not_support,Toast.LENGTH_SHORT).show();
                }
                startActivityForResult(intent, 0);
            }
        });
    }

    public void initViews() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            dialog.dismiss();
            initViews();
        }
    }
}